//
//  User.swift
//  SeeFM_Swift
//
//  Created by CBCT_MBP on 2021/6/25.
//

let kUserInfo: String = "kUserInfoKey"

import UIKit

class AppUser: HandyJSON {
    
    required init() {
    }
    
    class func userInfo() -> UserInfo? {
        let data = UserDefaults.standard.value(forKey: kUserInfo)
        guard let d = data else { return nil }
        let json = String.init(data: d as! Data, encoding: .utf8)
        let m = UserInfo.deserialize(from: json)
        return m
    }
    
    class func saveUser(info: UserInfo?) {
        guard let v = info else { return }
        let json = v.toJSONString()
        UserDefaults.standard.setValue(json, forKey: kUserInfo)
    }
    
    class func deleteUser() {
        UserDefaults.standard.removeObject(forKey: kUserInfo)
    }
    
}



// MARK: 用户信息
struct UserInfo: HandyJSON {
    
    var age: String?
    var avatar: String?
    var birthday: String?
    var cover: String?
    var city: String?
    var fans: String?
    var gender: String?
    var ID: String?
    var invite: String?
    var is_free: String?
    var mobile: String?
    var nickname: String?
    var openid: String?
    var slogan: String?
    var stars: String?
    var status: String?
    var username: String?
    var number: String?
    var verified: String?
    var salt: String?
    var token: String?
    var star: String?
    var first_login: String?
    var account_id: String?
    var constellation: String?
    var lastMonthRank: String?
    var lastMonth: String?
    var chief: String?
    var is_chief: String?
    var unicom: String?
    var user_mob: String?
    var unicom_url: String?
    var act_entrance: String?
    var act_switch: String?
    var setting_pwd: String?
    var balance: String?
    var order_url: String?
    var cart_url: String?
    var collect_url: String?
    var ds_token: String?
    var ds_expires_time: String?
    var is_follow: String?
    var is_follow_me: String?
    var join: String?
    var mutual: String?
    var followStatus: String?
    var is_live: String?
    var live_type: String?
    var plat: String?
    var realname: String?
    var group_id: String?
    var pub_source: String?
    var province_id: String?
    var city_id: String?
    var day: String?
    var friends: String?
    var host_active: String?
    var host_rank: String?
    var visit: String?
    var programme_live: String?
    var moment: String?
    var like: String?
    var fission_url: String?
    var is_new_visit: String?
    var shop_url: String?
    var store_opened_url: String?
    var radio_name: String?
    var club_name: String?
    var workcount: String?
    var profit_url: String?
    var data_url: String?
    var radio_activity_url: String?
    var is_pop: String?
    var content: String?
    var is_reporter: String?
    var qr_code_url: String?
    var fans_club_count: String?
    var shop_product_count: String?
    
    var badge: UserMedal?
    var protocolString: String?
    
    // 修改映射关系
    mutating func mapping(mapper: HelpingMapper) {
        mapper.specify(property: &protocolString, name: "protocol")
    }
    
}


struct UserMedal : HandyJSON {
    
    var name: String?
    var img: String?
    var asset: UIImage?
    var type: String?
    
}
